package com.goods.business.converter;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.goods.business.service.ManageService;
import com.goods.common.model.business.ProductCategory;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductCategoryTreeNodeVO;
import com.goods.common.vo.business.ProductCategoryVO;
import com.goods.common.vo.business.ProductVO;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/business/productCategory")
public class ManageController {
    @Autowired
    private ManageService manageService;

    //类别列表展示
    @GetMapping("/categoryTree")
    public ResponseBean categoryTree(@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "5") Integer pageSize){
        PageVO<ProductCategoryTreeNodeVO> pageVo = manageService.categoryTree(pageNum,pageSize);
        return ResponseBean.success(pageVo);
    }

    /*//类别列表展示
    @GetMapping("/categoryTree")
    public ResponseBean<PageInfo<ProductCategory>> categoryTree(@RequestParam(defaultValue = "1") Integer pageNum,
                                                                @RequestParam(defaultValue = "5") Integer pageSize,
                                                                ProductCategoryTreeNodeVO productCategoryTreeNodeVO){
        PageHelper.startPage(pageNum,pageSize);
        List<ProductCategory> productCategoryList = manageService.categoryTree(productCategoryTreeNodeVO);
        PageInfo<ProductCategory> info = new PageInfo<>(productCategoryList);
        return ResponseBean.success(info);
    }*/

    //获取父级分类下拉列表
    @GetMapping("/getParentCategoryTree")
    public ResponseBean getParentCategoryTree() {
        List<ProductCategoryTreeNodeVO> productCategoryList = manageService.getParentCategoryTree();
        return ResponseBean.success(productCategoryList);
    }

    //添加分类
    @PostMapping("/add")
    public ResponseBean add(@RequestBody ProductCategoryVO productCategoryVO){
        manageService.add(productCategoryVO);
        return ResponseBean.success();
    }

    //编辑分类
    @GetMapping("/edit/{id}")
    public ResponseBean edit(@PathVariable Long id){
        ProductCategoryVO productCategoryVO = manageService.edit(id);
        return ResponseBean.success(productCategoryVO);
    }

    //修改分类
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,@RequestBody ProductCategoryVO productCategoryVO){
        manageService.update(id,productCategoryVO);
        return ResponseBean.success();
    }

    //删除分类
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id) {
        manageService.delete(id);
        return ResponseBean.success();
    }


}
